package org.wadael.waverobotfrmwrk.simple;

import org.wadael.waverobotfrmwrk.meta.RobotTemplateServlet;

import com.google.wave.api.Blip;
import com.google.wave.api.Event;
import com.google.wave.api.RobotMessageBundle;
/**
 * Class to subclass in order to implement a simple robot of type Appender
 * See WIKI for the different robot types. 
 * 
 * @author jerome baton : Wadael, http://blog.wadael.org
 *
 */
public abstract class BlipAppenderRobot extends RobotTemplateServlet {

	private static final long serialVersionUID = 5660854981346084071L;

	@Override
	protected void reactToSubmittedBlip(RobotMessageBundle bundle, Blip bleep,Event event) 
	{
		Blip blip = event.getBlip();
		String eventualNewBlipText = getTextToAppend(blip.getDocument().getText());
		if (eventualNewBlipText != null) {
			Blip bliip = blip.createChild();
			bliip.getDocument().append(eventualNewBlipText);
		}
	}

	/**
	 * @return a String that will form a new blip, itself the child of the blip
	 *         YOUR code will react from. Or null if no new blip should be added
	 */
	protected abstract String getTextToAppend(String textOfTheBlipToReactFrom);

}
